package com.baomidou.ant.service.impl;

import com.baomidou.ant.common.Search;
import com.baomidou.ant.entity.PvpMessage;
import com.baomidou.ant.entity.PvpRecord;
import com.baomidou.ant.entity.PvpRoom;
import com.baomidou.ant.entity.User;
import com.baomidou.ant.mapper.PvpRecordMapper;
import com.baomidou.ant.service.IPvpInfoService;
import com.baomidou.ant.service.IPvpRecordService;
import com.baomidou.ant.service.IPvpRoomService;
import com.baomidou.ant.service.IUserService;
import com.baomidou.ant.utils.CheckLevelUtils;
import com.baomidou.ant.vo.Request.UserIdRequestVo;
import com.baomidou.ant.vo.Response.AllConnectUserVo;
import com.baomidou.ant.vo.Response.MyRecordVo;
import com.baomidou.ant.vo.Response.ResponseUserListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@Service(value = "pvpRecordService")
public class PvpRecordServiceImpl extends ServiceImpl<PvpRecordMapper, PvpRecord> implements IPvpRecordService {


    @Override
    public PvpRecord getByUserId(Integer userId) {
        QueryWrapper<PvpRecord> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<PvpRecord> pvpRecordList=list(queryWrapper);
        return pvpRecordList.get(0);
    }

    @Override
    public MyRecordVo checkMyRecord(Integer userId) {
        PvpRecord pvpRecord=this.getByUserId(userId);
        //定义返回结果
        MyRecordVo vo=new MyRecordVo();
        vo.setTotal(pvpRecord.getTotal());
        Double rate=(double)pvpRecord.getWin()/(double)pvpRecord.getTotal()*100;
        vo.setWinningRate(Double.parseDouble(String.format("%.2f",rate)));
        //vo.setWinningRate((float)pvpRecord.getWin()/(float)pvpRecord.getTotal()*100);
        vo.setLevel(CheckLevelUtils.pushLevel(pvpRecord.getWinning()));
        vo.setMoreWinning(pvpRecord.getWinning()%100);
        return vo;
    }


}
